package general.helperclasses;

import general.datastructures.Rectangle;
import general.datastructures.Vector2f;

public class Math {

	public static float mapToWorld(float f, int tilesize)
	{
		return (f * tilesize)-(tilesize/2);
	}

	public static Vector2f mapToWorld(Vector2f vec, int tilesize)
	{
		return vec.scale_cpy(tilesize).add_cpy(new Vector2f(-tilesize/2));
	}
	
	public static float worldToMap(float f, int tilesize)
	{
		return (int)(f / (float)tilesize);
	}
	
	public static Vector2f worldToMap(Vector2f vec, int tilesize)
	{
		return (vec.scale_cpy(1/(float)tilesize)).round_cpy();
	}
	
	public static float worldToScreen(float f, float viewport)
	{
		return f - viewport;
	}
	
	public static Vector2f worldToScreen(Vector2f vec, Rectangle viewport)
	{
		return Vector2f.subtract(vec, viewport.getOrigin());
	}
	
	public static Rectangle worldToScreen(Rectangle rec, Rectangle viewport)
	{
		return new Rectangle(Vector2f.subtract(rec.getOrigin(),viewport.getOrigin()), rec.getWidth(), rec.getHeight());
	}
	
	public static float screenToWorld(float f, float viewport)
	{
		return f + viewport;
	}
	
	public static Vector2f screenToWorld(Vector2f vec, Rectangle viewport)
	{
		return vec.add_cpy(viewport.getOrigin());
	}
	
	public static Rectangle screenToWorld(Rectangle rec, Rectangle viewport)
	{
		return new Rectangle(Vector2f.add(rec.getOrigin(),viewport.getOrigin()), rec.getWidth(), rec.getHeight());
	}
	
	public static float mapToScreen(float f, float viewport, int tilesize)
	{
		return worldToScreen(mapToWorld(f, tilesize), viewport);
	}
	
	public static float screenToMap(float f, float viewport, int tilesize)
	{
		return worldToMap(screenToWorld(f, viewport), tilesize);
	}
	
	public static Vector2f screenToMap(Vector2f vec, Rectangle viewport, int tilesize)
	{
		return worldToMap(screenToWorld(vec, viewport), tilesize);
	}
	
}
